package com.matt.controller.pad;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.domain.SaleFAQ;
import com.matt.foundation.constant.PermissionConstant;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.foundation.utils.annotation.RequiredPermissions;
import com.matt.service.SaleFAQService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.matt.foundation.constant.RequestConstant.TICKET;


@RestController
@RequestMapping("/pad/saleFAQ")
@Slf4j
public class PadSaleFAQController {

    @Autowired
    private SaleFAQService saleFAQService;

    @Autowired
    private MemVerificationCache cache;


    @RequestMapping("/getPage")
    public StatusResponse page(@RequestHeader(TICKET) String ticket, String keyWords ,PagerQuery query ){
    	String areaId = cache.getAreaId(ticket);  
        Page<SaleFAQ> recordPage = saleFAQService.getPageList(areaId,keyWords,query.getPageNum(), query.getPageSize());
        return StatusResponse.success(recordPage);
    }


    @RequestMapping("/add")
    public StatusResponse add(@RequestHeader(TICKET) String ticket, String question, String answer ){
    	StaffDTO staff = cache.getStaff(ticket);
        return StatusResponse.success(saleFAQService.add(staff.getAreaId(), staff.getId(), staff.getRealName(), question, answer));
    }


    @RequestMapping("/getPageByStaffId")
    public StatusResponse getPageByStaffId(@RequestHeader(TICKET) String ticket,PagerQuery query){
    	String staffId = cache.getStaffId(ticket);       
        return StatusResponse.success(saleFAQService.getPageListByStaffId(staffId,query.getPageNum(), query.getPageSize()));
    }

    @RequestMapping("/getPageByState")
    @RequiredPermissions(PermissionConstant.CRM_SALESFAQ_AUDITY)
    public StatusResponse getPageByState(@RequestHeader(TICKET) String ticket,PagerQuery query){
    	String areaId = cache.getAreaId(ticket);

        return StatusResponse.success(saleFAQService.getPageListByState(areaId,query.getPageNum(), query.getPageSize()));
    }


    @RequestMapping("/updateById")
    @RequiredPermissions(PermissionConstant.CRM_SALESFAQ_UPDATE)
    public StatusResponse updateById(@RequestHeader(TICKET) String ticket,String id,Integer state){

        String staffId = cache.getStaffId(ticket);
        return StatusResponse.success(saleFAQService.updateById(id, state, staffId));

    }
    
    @RequestMapping("/getById")
    public StatusResponse getById(@RequestHeader(TICKET) String ticket,String id){
   	
        	return StatusResponse.success(saleFAQService.getById(id));
        
    }

}
